package com.jinshan.common.result;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
 * @ClassName : BasePageResponse
 * @Description : 返回带分页信息的结果集
 * @Author : liujinshan
 * @Date: 2020-05-18 08:36
 */
public class BasePageResponse<T> {

    private List<T> datas;

    private String errCode;

    private String errMsg;

    private long currentPage;

    private long pageSize;

    private long total;

    public BasePageResponse() {
    }

    public BasePageResponse(List<T> list, String errCode, String errMsg, Integer currentPage, Integer pageSize, Integer total) {
        this.datas = list;
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.total = total;
    }

    @SuppressWarnings("unchecked")
    public static BasePageResponse ok (IPage page) {
        BasePageResponse basePageResponse = new BasePageResponse();
        basePageResponse.setDatas(page.getRecords());
        basePageResponse.setPageSize(page.getSize());
        basePageResponse.setCurrentPage(page.getCurrent());
        basePageResponse.setTotal(page.getTotal());
        basePageResponse.setErrCode("200");
        basePageResponse.setErrMsg("成功");
        return basePageResponse;
    }

    @SuppressWarnings("unchecked")
    public static BasePageResponse ok(List list){
        BasePageResponse b = new BasePageResponse();
        b.setDatas(list);
        b.setErrCode("200");
        b.setErrMsg("成功");
        return b;
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }

    public String getErrCode() {
        return errCode;
    }

    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public long getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(long currentPage) {
        this.currentPage = currentPage;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }
}
